<?php
/**
* @file $Id: WrapTabs.fnc.php 437 2007-04-23 00:57:51Z focus-sis $
* @package Focus/SIS
* @copyright Copyright (C) 2006 Andrew Schmadeke. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.txt
* Focus/SIS is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.txt for copyright notices and details.
*/

function WrapTabs($tabs,$selected="",$title="",$use_blue = false) 
{
	if($color == '' || $color == 'FFFFFF') 
		$color = "FFFFCC";
	
	$row = 0;
     	$characters = 0;
	$rows[0] = "<TABLE border=0 cellpadding=0 cellspacing=0><TR><TD width=4></TD>";
	if(count($tabs))
	{
		foreach($tabs as $tab)
		{
			if(substr($tab['title'],0,1)!='<')
				$tab_len = strlen($tab['title']);
			else
				$tab_len = 0;

			if($characters + $tab_len >= 120)
			{
				$rows[$row] .= "</TR>\n</TABLE>\n\n";
				$row++;
				$rows[$row] .= "\n<TABLE border=0 cellpadding=0 cellspacing=0 style='display:inline;'>\n\t<TR>";
				$characters = 0;
			}
			
			if($tab['link']==PreparePHP_SELF() || $tab['link']==$selected)
				$rows[$row] .= "<!--BOTTOM-->\n\t\t<TD>" . DrawTab($tab['title'],$tab['link']) . "</TD><TD width=4></TD>";
			elseif($use_blue!==true)
				$rows[$row] .= "\n\t\t<TD valign=bottom>" . DrawTab($tab['title'],$tab['link'],'DDDDDD','000000') . "</TD><TD width=4></TD>";
			else
				$rows[$row] .= "\n\t\t<TD valign=bottom>" . DrawTab($tab['title'],$tab['link']) . "</TD><TD width=4></TD>";
	
			$characters += $tab_len + 6;
		}
	}
	$rows[$row] .= "</TR>\n</TABLE>\n\n";
	
	$i = 0;
	$row_count = count($rows) - 1;
	if($use_blue===true)
		$table .= "\n<TABLE border=0 width=100% cellpadding=0 cellspacing=0><TR><TD width=100%></TD><TD align=".ALIGN_RIGHT.">";
	elseif($use_blue=='center')
		$table .= "\n<TABLE border=0 width=100% cellpadding=0 cellspacing=0 align=center><TR><TD align=center>";
	
	if($row_count>=1)
	{
		for($key=$row_count;$key>=0;$key--)
		{
			if(!ereg("<!--BOTTOM-->",$rows[$key]))
			{
				$table .= "\n<TABLE border=0 width=0 cellpadding=0 cellspacing=0><TR><TD>";
				$table .= "<IMG SRC=assets/pixel_trans.gif width=" . (($row_count-$i)*6) . " height=1>";
				if($key != 0 || $bottom)
					$table .= "</TD><TD>$rows[$key]</TD><TD rowspan=2>&nbsp;</TD></TR><TR><TD height=1></TD><TD height=5 valign=top></TD></TR></TABLE>\n";
				else
					$table .= "</TD><TD>$rows[$key]</TD><TD rowspan=2></TD></TR><TR><TD height=0></TD><TD height=0 valign=top></TD></TR></TABLE>\n";				
				$i++;
			}
			else
				$bottom = $key;
		}
		$table .= "<TABLE border=0 cellpadding=0 cellspacing=0 style='display:inline;'><TR><TD></TD><TD>" . $rows[$bottom] . "</TD><TD></TD></TR></TABLE>\n";
	}
	else
		$table .= $rows[0];

	if($use_blue)
		$table .= "</TD></TR><TR><TD colspan=2>";

	if($title!='')
		$table .= "<TABLE width=100% bgcolor=#$color border=0 cellpadding=0 cellspacing=0><TR><TD bgcolor=#$color width=100%> &nbsp;<font class=FontBox>$title</font></TD></TR></TABLE>\n";
	
	if($use_blue)
		$table .= "</TD></TR></TABLE>\n";
			
	return $table;
}

?>